package pongtests;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import cs343.HighScores;
import cs343.Score;

public class HighScores_Test {
	static HighScores highScores1;
	static HighScores highScores2;
	
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		highScores1 = new HighScores();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		highScores2 = new HighScores();
	}

	@After
	public void tearDown() throws Exception {
		highScores1 = null;
	}

	@Test
	public final void testUpdateScores() {
		List<Score> testList = new ArrayList<Score>();
		testList.add(new Score(0, "WIN"));
		testList.add(new Score(5, "WIN"));
		testList.add(new Score(2, "WIN"));
		testList.add(new Score(3, "WIN"));
		testList.add(new Score(1, "WIN"));
		testList.add(new Score(4, "WIN"));
		highScores1.setHighScores(testList);
		testList = new ArrayList<Score>();
		testList.addAll(highScores1.getHighScores());
		highScores1.updateScores(new Score(6, "NOO"));
		testList.add(new Score(6, "NOO"));
		Collections.sort(testList);
		Collections.reverse(testList);
		for(int i = 0; i < testList.size(); i++){
			assertEquals(highScores1.getHighScores().get(i).getScore(), testList.get(i).getScore());
			assertEquals(highScores1.getHighScores().get(i).getAlias(), testList.get(i).getAlias());
		}

	}

	@Test
	public final void testCheckScore() {
		List<Score> testList = new ArrayList<Score>();
		testList.add(new Score(10, "WIN"));
		testList.add(new Score(10, "WIN"));
		testList.add(new Score(10, "WIN"));
		testList.add(new Score(10, "WIN"));
		highScores2.setHighScores(testList);
		assertEquals(highScores2.checkScore(50), true);
		assertEquals(highScores2.checkScore(0), true);
		testList.add(new Score(10, "WIN"));
		testList.add(new Score(10, "WIN"));
		testList.add(new Score(10, "WIN"));
		testList.add(new Score(10, "WIN"));
		testList.add(new Score(10, "WIN"));
		testList.add(new Score(10, "WIN"));
		testList.add(new Score(10, "WIN"));
		highScores2.setHighScores(testList);
		assertEquals(highScores2.checkScore(0), false);

	}

}
